package com.dougs.timehandler.receiver;

import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class LockScreenReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("Lock", "onReceive: 接收锁屏广播");

        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName componentName = new ComponentName(context, LockDeviceAdminReceiver.class);
        if (devicePolicyManager.isAdminActive(componentName)) {
            Log.i("Lock", "onReceive: 启动锁屏");
            devicePolicyManager.lockNow();
        }
    }

}
